﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="/js/header.js"></script>
</head>
<body style="background-color: white;">
    <div class="data-wrap" style="margin:5px;">
        <div class="form-group" style="padding: 10px 15px;">
            <div class="t_c hide" id="opt">
                <button class="btn btn-warning m10_l" name="turnfailure">转失败</button>
                <button class="btn btn-primary m10_l" name="turnsuccess">转成功</button>
                <button class="btn btn-danger m10_l" name="renewpayment">重新推送</button>
                <pre class="p10 m10_t">「重新推送」前请务必与秒付宝客服确认！</pre>
            </div>
            <div class="t_c hide m5_t" id="tip">
                <pre id="tip" class="p20">请确认3分钟后重试</pre>
            </div>
        </div>
    </div>
    
    <script type="text/javascript">
        var parent = artDialog.open.origin;

        var orderNo;

        $(function () {
            orderNo = FlashPay.Util.GetQueryString("orderNo");

            init();

            $("#btnSearch").click(function () {
                init();
            });
        
            //转失败
            $("button[name='turnfailure']").click(function () {

                FlashPay.UI.Confirm({
                    content: "确定要<span class='red'>转失败</span>该订单吗？",
                    ok: function () {

                        var cover = FlashPay.UI.Mask({
                            obj: $("body"),
                            opacity: 0.5
                        });

                        FlashPay.Util.Ajax({
                            type: "POST",
                            url: "/Payment/YFTTurnFailure",
                            data: { orderNo: orderNo },
                            dataType: "json",
                            success: function (response) {
                                if (response != null && response.success) {
                                    FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                                    FlashPay.UI.DialogOpener().doSearch();
                                    FlashPay.UI.CloseDialog();
                                } else {
                                    cover.Remove();
                                    FlashPay.UI.DialogOpener().doSearch();
                                    FlashPay.UI.Tip_short_warning("操作失败:" + response.errorMessage);
                                }
                            },
                            error: function (e) {
                                cover.Remove();

                                FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试！");
                            }
                        });

                    }
                });

                
            });
            //转成功
            $("button[name='turnsuccess']").click(function () {

                FlashPay.UI.Confirm({
                    content: "确定要<span class='red'>转成功</span>该订单吗？",
                    ok: function () {

                        var cover = FlashPay.UI.Mask({
                            obj: $("body"),
                            opacity: 0.5
                        });

                        FlashPay.Util.Ajax({
                            type: "POST",
                            url: "/Payment/BVVTurnSuccess",
                            data: { orderNo: orderNo},
                            dataType: "json",
                            success: function (response) {
                                if (response != null && response.success) {
                                    FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                                    FlashPay.UI.DialogOpener().doSearch();
                                    FlashPay.UI.CloseDialog();
                                } else {
                                    cover.Remove();

                                    FlashPay.UI.Tip_short_warning("操作失败:" + response.errorMessage);
                                }
                            },
                            error: function (e) {
                                cover.Remove();

                                FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试！");
                            }
                        });

                    }
                });

                
            });
            //重新付款
            $("button[name='renewpayment']").click(function () {

                FlashPay.UI.Confirm({
                    content: "确定要<span class='red'>重新付款</span>该订单吗？",
                    ok: function () {

                        var cover = FlashPay.UI.Mask({
                            obj: $("body"),
                            opacity: 0.5
                        });

                        FlashPay.Util.Ajax({
                            type: "POST",
                            url: "/Payment/BVVRenewPayment",
                            data: { orderNo: orderNo },
                            dataType: "json",
                            success: function (response) {
                                if (response != null && response.success) {
                                    FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                                    FlashPay.UI.DialogOpener().doSearch();
                                    FlashPay.UI.CloseDialog();
                                } else {
                                    cover.Remove();
                                    FlashPay.UI.DialogOpener().doSearch();
                                    FlashPay.UI.Tip_short_warning("操作失败:" + response.errorMessage);
                                }
                            },
                            error: function (e) {
                                cover.Remove();

                                FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试！");
                            }
                        });

                    }
                });

            });
        });

        function init() {

            var cover = FlashPay.UI.Mask({
                obj: $("body"),
                opacity: 0.5
            });

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/Payment/YFTPaymentRecord?orderNo=" + orderNo,
                data: null,
                dataType: "json",
                success: function (response) {
                    cover.Remove();
                    if (response != null && response.success) {
                        if (response.data != null && response.data.isRenewPayment && response.data.paymentDateTimeDifference > 3) {
                            $("div#opt").removeClass("hide");
                        } else {
                            $("#tip").removeClass("hide");
                        }
                    } else {
                        cover.Remove();
                        $("div#opt").removeClass("hide");
                        FlashPay.UI.Tip_short_warning(response.errorMessage);
                    }
                },
                error: function (e) {
                    cover.Remove();

                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试！");
                }
            });
        }
    </script>
</body>
</html>